package com.dianning.web.action.house;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.*;

import com.dianning.bean.Area;
import com.dianning.bean.ChannelContact;
import com.dianning.bean.Company;
import com.dianning.bean.Info;
import com.dianning.bean.InfoExpand;
import com.dianning.bean.Money;
import com.dianning.bean.Parameter;
import com.dianning.bean.Profile;
import com.dianning.bean.Resume;
import com.dianning.bean.TradingArea;
import com.dianning.bean.UserDetail;
import com.dianning.bean.UserInfo;
import com.dianning.bean.Visitor;
import com.dianning.comm.ChannelConfig;
import com.dianning.comm.Constant;
import com.dianning.comm.DianningUtil;
import com.dianning.comm.OrderObj;
import com.dianning.comm.Util;
import com.dianning.exception.DianningException;
import com.dianning.service.AreaService;
import com.dianning.service.ChannelService;
import com.dianning.service.InfoService;
import com.dianning.service.ParameterService;
import com.dianning.service.UserInfoService;
import com.dianning.service.VisitorService;
import com.dianning.service.web.PageList;
import com.dianning.service.web.Pages;
import com.dianning.web.action.BaseAction;
import com.dianning.web.interceptor.RemoteAddrAware;
import com.dianning.web.interceptor.UserSessionAware;
import com.dianning.web.servlet.UserSession;
import com.dianning.web.ui.CheckboxLong;
import com.dianning.web.ui.OptionsInt;
import com.dianning.web.ui.OptionsLong;
import com.dianning.web.ui.OptionsString;

public class Hezu extends BaseAction implements UserSessionAware{

	private static final Log logger = LogFactory.getLog(Hezu.class);
	
	private InfoService infoService;
	private ChannelService channelService;
	private ParameterService parameterService;
	private AreaService areaService;
	private UserInfoService userInfoService;


	public InfoService getInfoService() {
		return infoService;
	}

	public void setInfoService(InfoService infoService) {
		this.infoService = infoService;
	}
	
	public ChannelService getChannelService() {
		return channelService;
	}

	public void setChannelService(ChannelService channelService) {
		this.channelService = channelService;
	}

	public ParameterService getParameterService() {
		return parameterService;
	}

	public void setParameterService(ParameterService parameterService) {
		this.parameterService = parameterService;
	}

	public AreaService getAreaService() {
		return areaService;
	}

	public void setAreaService(AreaService areaService) {
		this.areaService = areaService;
	}

	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	
	
	private UserSession userSession;

	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	private List houseTypeList = new ArrayList();
	private List houseFitTypeList = new ArrayList();
	private List houseHireroomTypeList = new ArrayList();
	private List houseTowardTypeList = new ArrayList();
	private List houseConfineTypeList = new ArrayList();
	private List houseHirepayTypeList = new ArrayList();
	private List houseAllocationList = new ArrayList();
	private List houseMetroTypeList = new ArrayList();
	
	public List getHouseTypeList() {
		return houseTypeList;
	}

	public void setHouseTypeList(List houseTypeList) {
		this.houseTypeList = houseTypeList;
	}

	public List getHouseFitTypeList() {
		return houseFitTypeList;
	}

	public void setHouseFitTypeList(List houseFitTypeList) {
		this.houseFitTypeList = houseFitTypeList;
	}

	public List getHouseTowardTypeList() {
		return houseTowardTypeList;
	}

	public void setHouseTowardTypeList(List houseTowardTypeList) {
		this.houseTowardTypeList = houseTowardTypeList;
	}

	public List getHouseHirepayTypeList() {
		return houseHirepayTypeList;
	}

	public void setHouseHirepayTypeList(List houseHirepayTypeList) {
		this.houseHirepayTypeList = houseHirepayTypeList;
	}

	public List getHouseHireroomTypeList() {
		return houseHireroomTypeList;
	}

	public void setHouseHireroomTypeList(List houseHireroomTypeList) {
		this.houseHireroomTypeList = houseHireroomTypeList;
	}

	public List getHouseConfineTypeList() {
		return houseConfineTypeList;
	}

	public void setHouseConfineTypeList(List houseConfineTypeList) {
		this.houseConfineTypeList = houseConfineTypeList;
	}

	public List getHouseAllocationList() {
		return houseAllocationList;
	}

	public void setHouseAllocationList(List houseAllocationList) {
		this.houseAllocationList = houseAllocationList;
	}

	public List getHouseMetroTypeList() {
		return houseMetroTypeList;
	}

	public void setHouseMetroTypeList(List houseMetroTypeList) {
		this.houseMetroTypeList = houseMetroTypeList;
	}
	
	private void setHouseTypeListValues(){
		List l = this.getParameterService().findParameters("houseType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseFitTypeListValues(){
		List l = this.getParameterService().findParameters("houseFitType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseFitTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseHireroomTypeListValues(){
		List l = this.getParameterService().findParameters("houseHireroomType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseHireroomTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseTowardTypeValues(){
		List l = this.getParameterService().findParameters("houseTowardType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseTowardTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseConfineTypeListValues(){
		List l = this.getParameterService().findParameters("houseConfineType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseConfineTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseHirepayTypeValues(){
		List l = this.getParameterService().findParameters("houseHirepayType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseHirepayTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseAllocationValues(){
		List l = this.getParameterService().findParameters("houseAllocation", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseAllocationList.add(new CheckboxLong(p.getId(), p.getParamName()));
		}
	}
	private void setHouseMetroTypeListValues(){
		List l = this.getParameterService().findParameters("houseMetroType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			houseMetroTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	
	private void initValues(){
		setHouseTypeListValues();
		setHouseFitTypeListValues();
		setHouseHireroomTypeListValues();
		setHouseTowardTypeValues();
		setHouseConfineTypeListValues();
		setHouseHirepayTypeValues();
		setHouseAllocationValues();
		setHouseMetroTypeListValues();
		this.setBigChannel(this.getChannelService().findChannelContactById(this.bid));
		this.setSmallChannel(this.getChannelService().findChannelContactById(this.sid));
		this.setArea(this.getAreaService().findAreaById(this.areaId));
		if(this.areaId == -1){
			this.areaId = 0;
		}
		if(this.tid == -1){
			this.tid = 0;
		}
		this.setTradingArea(this.getAreaService().findTradingAreaById(this.tid));
	}

	
	private long id;
	private long bid = ChannelConfig.HOUSE_ID;
	private long sid = ChannelConfig.HOUSE_HEZU_ID;
	private long areaId = -1;
	private long allTop = 1;
	private long tid = -1;
	private String title = "";
	private long hireType;
	private String housing = "";
	private int isbiz = -1;
	private boolean biz = false;
	private boolean profile = true;
	private long room = -1;
	private long parlor;
	private long wc;
	private long floor;
	private long totalfloor;
	private String minPrice = "";
	private String maxPrice = "";
	private String mianji = "";
	private String content;
	private List photo;
	private int photonum;
	private String linkman;
	private String phone;
	private String typeid;
	private long houseType;
	private long houseFitType;
	private long houseHireroomType;
	private long houseTowardType;
	private long houseConfineType;
	private long houseHirepayType;
	private List houseAllocation;
	private long houseMetroType = -1;
	
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getBid() {
		return bid;
	}

	public void setBid(long bid) {
		this.bid = bid;
	}

	public long getSid() {
		return sid;
	}

	public void setSid(long sid) {
		this.sid = sid;
	}public long getAreaId() {
		return areaId;
	}

	public void setAreaId(long areaId) {
		this.areaId = areaId;
	}

	public long getAllTop() {
		return allTop;
	}

	public void setAllTop(long allTop) {
		this.allTop = allTop;
	}


	public long getTid() {
		return tid;
	}

	public void setTid(long tid) {
		this.tid = tid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getIsbiz() {
		return isbiz;
	}

	public void setIsbiz(int isbiz) {
		this.isbiz = isbiz;
	}

	public boolean isBiz() {
		return biz;
	}

	public void setBiz(boolean biz) {
		this.biz = biz;
	}

	public boolean isProfile() {
		return profile;
	}

	public void setProfile(boolean profile) {
		this.profile = profile;
	}


	public long getRoom() {
		return room;
	}

	public void setRoom(long room) {
		this.room = room;
	}

	public String getMinPrice() {
		return minPrice;
	}

	public void setMinPrice(String minPrice) {
		this.minPrice = minPrice;
	}

	public String getMaxPrice() {
		return maxPrice;
	}

	public void setMaxPrice(String maxPrice) {
		this.maxPrice = maxPrice;
	}

	public String getMianji() {
		return mianji;
	}

	public void setMianji(String mianji) {
		this.mianji = mianji;
	}

	public String getHousing() {
		return housing;
	}

	public void setHousing(String housing) {
		this.housing = housing;
	}

	public long getParlor() {
		return parlor;
	}

	public void setParlor(long parlor) {
		this.parlor = parlor;
	}

	public long getWc() {
		return wc;
	}

	public void setWc(long wc) {
		this.wc = wc;
	}

	public long getFloor() {
		return floor;
	}

	public void setFloor(long floor) {
		this.floor = floor;
	}

	public long getTotalfloor() {
		return totalfloor;
	}

	public void setTotalfloor(long totalfloor) {
		this.totalfloor = totalfloor;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public List getPhoto() {
		return photo;
	}

	public void setPhoto(List photo) {
		this.photo = photo;
	}

	public int getPhotonum() {
		return photonum;
	}

	public void setPhotonum(int photonum) {
		this.photonum = photonum;
	}

	public String getLinkman() {
		return linkman;
	}

	public void setLinkman(String linkman) {
		this.linkman = linkman;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getTypeid() {
		return typeid;
	}

	public void setTypeid(String typeid) {
		this.typeid = typeid;
	}

	public long getHireType() {
		return hireType;
	}

	public void setHireType(long hireType) {
		this.hireType = hireType;
	}

	public long getHouseHireroomType() {
		return houseHireroomType;
	}

	public void setHouseHireroomType(long houseHireroomType) {
		this.houseHireroomType = houseHireroomType;
	}

	public long getHouseConfineType() {
		return houseConfineType;
	}

	public void setHouseConfineType(long houseConfineType) {
		this.houseConfineType = houseConfineType;
	}

	public long getHouseType() {
		return houseType;
	}

	public void setHouseType(long houseType) {
		this.houseType = houseType;
	}

	public long getHouseFitType() {
		return houseFitType;
	}

	public void setHouseFitType(long houseFitType) {
		this.houseFitType = houseFitType;
	}

	public long getHouseTowardType() {
		return houseTowardType;
	}

	public void setHouseTowardType(long houseTowardType) {
		this.houseTowardType = houseTowardType;
	}

	public long getHouseHirepayType() {
		return houseHirepayType;
	}

	public void setHouseHirepayType(long houseHirepayType) {
		this.houseHirepayType = houseHirepayType;
	}

	public List getHouseAllocation() {
		return houseAllocation;
	}

	public void setHouseAllocation(List houseAllocation) {
		this.houseAllocation = houseAllocation;
	}

	
	private Info info;
	private List sameAreas;
	private List sameUsers;
	private PageList pageList;
	private List areas;
	private String domain = Constant.DOMAIN;
	private String profileDomain = Constant.PROFILE_DOMAIN;
	private ChannelContact bigChannel;
	private ChannelContact smallChannel;
	private Area area;
	private TradingArea tradingArea;
	private List houseAllocations;
	private List houseMetroTypes;

	public long getHouseMetroType() {
		return houseMetroType;
	}

	public void setHouseMetroType(long houseMetroType) {
		this.houseMetroType = houseMetroType;
	}
	
	public Info getInfo() {
		return info;
	}

	public void setInfo(Info info) {
		this.info = info;
	}
	
	public List getSameAreas() {
		return sameAreas;
	}

	public void setSameAreas(List sameAreas) {
		this.sameAreas = sameAreas;
	}

	public List getSameUsers() {
		return sameUsers;
	}

	public void setSameUsers(List sameUsers) {
		this.sameUsers = sameUsers;
	}

	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}

	public List getAreas() {
		return areas;
	}

	public void setAreas(List areas) {
		this.areas = areas;
	}
	

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getProfileDomain() {
		return profileDomain;
	}

	public void setProfileDomain(String profileDomain) {
		this.profileDomain = profileDomain;
	}

	public ChannelContact getBigChannel() {
		return bigChannel;
	}

	public void setBigChannel(ChannelContact bigChannel) {
		this.bigChannel = bigChannel;
	}

	public ChannelContact getSmallChannel() {
		return smallChannel;
	}

	public void setSmallChannel(ChannelContact smallChannel) {
		this.smallChannel = smallChannel;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public TradingArea getTradingArea() {
		return tradingArea;
	}

	public void setTradingArea(TradingArea tradingArea) {
		this.tradingArea = tradingArea;
	}

	public List getHouseAllocations() {
		return houseAllocations;
	}

	public void setHouseAllocations(List houseAllocations) {
		this.houseAllocations = houseAllocations;
	}

	public List getHouseMetroTypes() {
		return houseMetroTypes;
	}

	public void setHouseMetroTypes(List houseMetroTypes) {
		this.houseMetroTypes = houseMetroTypes;
	}
	

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return ERROR;
		}
	}

	public String index(){
		this.setInfo(this.getInfoService().findInfoById(this.id));
		if(this.getInfo() == null){
			return "infodisable";
		}else{
			if(this.getInfo().getValidated() == 2){
				return "infodisable";
			}
		}
		this.setSameAreas(this.getInfoService().findInfos(id,-1, this.getInfo().getCcid(), 1, 1, -1, "addTime", 1, 1, 5));
		this.setSameUsers(this.getInfoService().findInfos(id,this.getInfo().getUid(), this.getInfo().getCcid(), 1, 1, -1, "addTime", 1, 1, 5));
		for(int i=0;i<this.info.getInfoExpands().size();i++){
			InfoExpand ex = (InfoExpand) this.info.getInfoExpands().get(i);
			if(ex.getKeyword().equalsIgnoreCase("houseAllocation")){
				if(StringUtils.isNotBlank(ex.getSvalue())){
					this.setHouseAllocations(this.getParameterService().findParameters("", 2, Util.string2List(ex.getSvalue()),"orders", 0));
				}
			}
		}
        return "index";
	}
	
	public String list(){
		if(this.areaId == 0){
			this.areaId = -1;
		}
		if(this.tid == 0){
			this.tid = -1;
		}
		if(this.room == 0){
			this.room = -1;
		}

		this.setAreas(this.getAreaService().findAreas("orders", 0));
		this.setHouseMetroTypes(this.getParameterService().findParameters("houseMetroType", 2, null, "orders", 0));
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/house/hezu.action?action=list&&areaId="+this.areaId+"&tid="+this.tid+"&isbiz="+this.isbiz+"&houseMetroType="+this.houseMetroType+"&hireType="+this.hireType+"&minPrice="+this.minPrice+"&maxPrice="+this.maxPrice+"&title="+this.title);
		List wherein = new ArrayList();
		if(hireType != -1){
			wherein.add("keyword='hireType' and ivalue="+hireType);
		}
		if(this.houseMetroType != -1){
			wherein.add("keyword='houseMetroType' and ivalue="+this.houseMetroType);		
		}
		if(StringUtils.isNotBlank(minPrice)){
			wherein.add("keyword='minPrice' and ivalue>="+(int)(Float.parseFloat(minPrice)*10));
		}
		if(StringUtils.isNotBlank(maxPrice)){
			wherein.add("keyword='minPrice' and ivalue<="+(int)(Float.parseFloat(maxPrice)*10));
		}
		OrderObj commend = new OrderObj();
		commend.setOrderBy("isCommend");
		commend.setAscOrDesc(1);
		OrderObj top = new OrderObj();
		if(this.areaId == -1){
			top.setOrderBy("isCityTop");
			top.setAscOrDesc(1);
		}else{
			this.allTop = -1;
			top.setOrderBy("isAreaTop");
			top.setAscOrDesc(1);
		}
		OrderObj up = new OrderObj();
		up.setOrderBy("upTime");
		up.setAscOrDesc(1);
		OrderObj[] oo = {commend,top,up};
		this.setPageList(this.getInfoService().findInfos(-1, -1, sid, areaId, tid, isbiz, 1, 1,-1,title, wherein, oo, pages));
		return "list";
	}
	
	public String post(){
		initValues();
		this.setAction("dopost");
		UserInfo ui = this.getUserInfoService().findUserInfoByUid(userSession.getUid());
		this.setLinkman(ui.getName());
		this.setPhone(ui.getUserDetail().getMobile());
		return "post";
	}
	
	public String dopost(){
		ChannelContact cc = this.getChannelService().findChannelContactById(this.sid);
		Info info = new Info();
		info.setCid(cc.getChannelId());
		info.setCcid(this.sid);
		info.setTitle(DianningUtil.filterKeyword(this.title));
		info.setContent(DianningUtil.filterKeyword(this.content));
		info.setAreaId(this.areaId);
		info.setTradingareaId(this.tid);
		info.setUid(this.userSession.getUid());
		info.setName(this.linkman);
		info.setTel(this.phone);
		info.setIsbiz(boolean2int(this.biz));
		info.setIsProfile(boolean2int(this.profile));
		info.setPhoto(this.photo);
		if(this.photo==null || this.photo.isEmpty()){
			info.setPhotonum(0);
		}else{
			info.setPhotonum(this.photo.size());
		}
		info.setAvatar("");
		info.setValidated(0);
		info.setStatus(1);
		info.setAddTime(new Date());
		info.setUpTime(new Date());
		info.setIsCityTop(0);
		info.setCityTopTime(new Date());
		info.setIsAreaTop(0);
		info.setAreaTopTime(new Date());
		info.setIsCommend(0);
		info.setCommendTime(new Date());	
		
		
		List infoExpands = new ArrayList();
		//hireType
		InfoExpand infoHireType = new InfoExpand();
		infoHireType.setKeyword("hireType");
		if(this.hireType==0){
			infoHireType.setSvalue("单间");
		}
		if(this.hireType==1){
			infoHireType.setSvalue("床位");
		}
		infoHireType.setIvalue(this.hireType);
		infoExpands.add(infoHireType);
		//housing
		InfoExpand infoHousing = new InfoExpand();
		infoHousing.setKeyword("housing");
		infoHousing.setSvalue(this.housing);
		infoHousing.setIvalue(0);
		infoExpands.add(infoHousing);
		//room
		InfoExpand infoRoom = new InfoExpand();
		infoRoom.setKeyword("room");
		infoRoom.setSvalue(String.valueOf(this.room));
		infoRoom.setIvalue(this.room);
		infoExpands.add(infoRoom);
		//parlor
		InfoExpand infoParlor = new InfoExpand();
		infoParlor.setKeyword("parlor");
		infoParlor.setSvalue(String.valueOf(this.parlor));
		infoParlor.setIvalue(this.parlor);
		infoExpands.add(infoParlor);
		//wc
		InfoExpand infoWc = new InfoExpand();
		infoWc.setKeyword("wc");
		infoWc.setSvalue(String.valueOf(this.wc));
		infoWc.setIvalue(this.wc);
		infoExpands.add(infoWc);
		//floor
		InfoExpand infoFloor = new InfoExpand();
		infoFloor.setKeyword("floor");
		infoFloor.setSvalue(String.valueOf(this.floor));
		infoFloor.setIvalue(this.floor);
		infoExpands.add(infoFloor);
		//totalfloor
		InfoExpand infoTotalfloor = new InfoExpand();
		infoTotalfloor.setKeyword("totalfloor");
		infoTotalfloor.setSvalue(String.valueOf(this.totalfloor));
		infoTotalfloor.setIvalue(this.totalfloor);
		infoExpands.add(infoTotalfloor);
		//mianji
		InfoExpand infoMianji = new InfoExpand();
		infoMianji.setKeyword("mianji");
		infoMianji.setSvalue(String.valueOf(this.mianji));
		if(StringUtils.isBlank(this.mianji)){
			infoMianji.setIvalue(0);
		}else{
			infoMianji.setIvalue((int)(Float.parseFloat(mianji)*10));
		}
		infoExpands.add(infoMianji);
		//minPrice
		InfoExpand infoMinPrice = new InfoExpand();
		infoMinPrice.setKeyword("minPrice");
		infoMinPrice.setSvalue(String.valueOf(this.minPrice));
		if(StringUtils.isBlank(this.minPrice)){
			infoMinPrice.setIvalue(0);
		}else{
			infoMinPrice.setIvalue((int)(Float.parseFloat(minPrice)*10));
		}
		infoExpands.add(infoMinPrice);
		//houseType
		Parameter pHouseType = this.getParameterService().findParameterById(this.houseType);
		InfoExpand infoHouseType = new InfoExpand();
		infoHouseType.setKeyword("houseType");
		infoHouseType.setSvalue(pHouseType.getParamName());
		infoHouseType.setIvalue(this.houseType);
		infoExpands.add(infoHouseType);
		//houseFitType
		Parameter pHouseFitType = this.getParameterService().findParameterById(this.houseFitType);
		InfoExpand infoHouseFitType = new InfoExpand();
		infoHouseFitType.setKeyword("houseFitType");
		infoHouseFitType.setSvalue(pHouseFitType.getParamName());
		infoHouseFitType.setIvalue(this.houseFitType);
		infoExpands.add(infoHouseFitType);
		//houseHireroomType
		Parameter pHouseHireroomType = this.getParameterService().findParameterById(this.houseHireroomType);
		InfoExpand infoHouseHireroomType = new InfoExpand();
		infoHouseHireroomType.setKeyword("houseHireroomType");
		infoHouseHireroomType.setSvalue(pHouseHireroomType.getParamName());
		infoHouseHireroomType.setIvalue(this.houseHireroomType);
		infoExpands.add(infoHouseHireroomType);
		//houseTowardType
		Parameter pHouseTowardType = this.getParameterService().findParameterById(this.houseTowardType);
		InfoExpand infoHouseTowardType = new InfoExpand();
		infoHouseTowardType.setKeyword("houseTowardType");
		infoHouseTowardType.setSvalue(pHouseTowardType.getParamName());
		infoHouseTowardType.setIvalue(this.houseTowardType);
		infoExpands.add(infoHouseTowardType);
		//houseConfineType
		Parameter pHouseConfineType = this.getParameterService().findParameterById(this.houseConfineType);
		InfoExpand infoHouseConfineType = new InfoExpand();
		infoHouseConfineType.setKeyword("houseConfineType");
		infoHouseConfineType.setSvalue(pHouseConfineType.getParamName());
		infoHouseConfineType.setIvalue(this.houseConfineType);
		infoExpands.add(infoHouseConfineType);
		//houseHirepayType
		Parameter pHouseHirepayType = this.getParameterService().findParameterById(this.houseHirepayType);
		InfoExpand infoHouseHirepayType = new InfoExpand();
		infoHouseHirepayType.setKeyword("houseHirepayType");
		infoHouseHirepayType.setSvalue(pHouseHirepayType.getParamName());
		infoHouseHirepayType.setIvalue(this.houseHirepayType);
		infoExpands.add(infoHouseHirepayType);
		//
		//houseAllocation
		InfoExpand infoHouseAllocation = new InfoExpand();
		infoHouseAllocation.setKeyword("houseAllocation");
		if(houseAllocation==null || houseAllocation.isEmpty()){
			infoHouseAllocation.setSvalue("");
		}else{
			infoHouseAllocation.setSvalue(Util.list2String(houseAllocation));
		}
		infoHouseAllocation.setIvalue(0);
		infoExpands.add(infoHouseAllocation);
		//houseMetroType
		Parameter pHouseMetroType = this.getParameterService().findParameterById(this.houseMetroType);
		InfoExpand infoHouseMetroType = new InfoExpand();
		infoHouseMetroType.setKeyword("houseMetroType");
		infoHouseMetroType.setSvalue(pHouseMetroType.getParamName());
		infoHouseMetroType.setIvalue(this.houseMetroType);
		infoExpands.add(infoHouseMetroType);
		
		info = this.getInfoService().saveInfo(info, infoExpands);
		this.id = info.getId();
		return "dopost";
	}
	
	public String update(){
		
		this.setAction("doupdate");
		this.setInfo(this.getInfoService().findInfoById(this.id));
		if(this.getInfo() == null){
			return "infodisable";
		}else{
			if(this.getInfo().getValidated() == 2){
				return "infodisable";
			}
		}
		ChannelContact cc = this.getChannelService().findChannelContactById(this.sid);
		this.bid = cc.getParentId();
		this.sid = this.info.getCcid();
		this.areaId = this.info.getAreaId();
		this.tid = this.info.getTradingareaId();
		this.title = this.info.getTitle();
		this.content = this.info.getContent();
		this.linkman = this.info.getName();
		this.phone = this.info.getTel();
		this.biz = int2boolean(this.info.getIsbiz());
		this.profile = int2boolean(this.info.getIsProfile());
		this.photo = this.info.getPhoto();
		this.photonum = this.info.getPhotonum();
		
		//housing
		InfoExpand infoHireType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "hireType");
		this.hireType = infoHireType.getIvalue();
		//housing
		InfoExpand infoHousing = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "housing");
		this.housing = infoHousing.getSvalue();
		//room
		InfoExpand infoRoom = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "room");
		this.room = infoRoom.getIvalue();
		//parlor
		InfoExpand infoParlor = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "parlor");
		this.parlor = infoParlor.getIvalue();
		//wc
		InfoExpand infoWc = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "wc");
		this.wc =infoWc.getIvalue();
		//floor
		InfoExpand infoFloor = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "floor"); 
		this.floor = infoFloor.getIvalue();
		//totalfloor
		InfoExpand infoTotalfloor = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "totalfloor");
		this.totalfloor = infoTotalfloor.getIvalue();
		//mianji
		InfoExpand infoMianji = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "mianji");
		this.mianji = infoMianji.getSvalue();
		//minPrice
		InfoExpand infoMinPrice = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "minPrice");
		this.minPrice = infoMinPrice.getSvalue();
		//houseType
		InfoExpand infoHouseType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseType");
		this.houseType = infoHouseType.getIvalue();
		//houseFitType
		InfoExpand infoHouseFitType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseFitType");
		this.houseFitType = infoHouseFitType.getIvalue();
		//houseHireroomType
		InfoExpand infoHouseHireroomType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseHireroomType");
		this.houseHireroomType = infoHouseHireroomType.getIvalue();
		//houseTowardType
		InfoExpand infoHouseTowardType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseTowardType");
		this.houseTowardType = infoHouseTowardType.getIvalue();
		//houseConfineType
		InfoExpand infoHouseConfineType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseConfineType");
		this.houseConfineType = infoHouseConfineType.getIvalue();
		//houseHirepayType
		InfoExpand infoHouseHirepayType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseHirepayType");
		this.houseHirepayType = infoHouseHirepayType.getIvalue();
		//houseAllocation
		InfoExpand infoHouseAllocation = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseAllocation"); 
		this.houseAllocation = Util.string2List(infoHouseAllocation.getSvalue());
		//houseMetroType
		InfoExpand infoHouseMetroType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseMetroType");
		this.houseMetroType = infoHouseMetroType.getIvalue();
		initValues();
		return "update";
	}

	public String doupdate(){
		ChannelContact cc = this.getChannelService().findChannelContactById(this.sid);
		Info info = this.getInfoService().findInfoById(this.id);
		info.setCid(cc.getChannelId());
		info.setCcid(this.sid);
		info.setTitle(DianningUtil.filterKeyword(this.title));
		info.setContent(DianningUtil.filterKeyword(this.content));
		info.setAreaId(this.areaId);
		info.setTradingareaId(this.tid);
		info.setUid(this.userSession.getUid());
		info.setName(this.linkman);
		info.setTel(this.phone);
		info.setIsbiz(boolean2int(this.biz));
		info.setIsProfile(boolean2int(this.profile));
		info.setPhoto(this.photo);
		if(this.photo==null || this.photo.isEmpty()){
			info.setPhotonum(0);
		}else{
			info.setPhotonum(this.photo.size());
		}			
		
		List infoExpands = new ArrayList();
		//hireType
		InfoExpand infoHireType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "hireType");
		infoHireType.setKeyword("hireType");
		if(this.hireType==0){
			infoHireType.setSvalue("单间");
		}
		if(this.hireType==1){
			infoHireType.setSvalue("床位");
		}
		infoHireType.setIvalue(this.hireType);
		infoExpands.add(infoHireType);
		//housing
		InfoExpand infoHousing = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "housing");
		infoHousing.setKeyword("housing");
		infoHousing.setSvalue(this.housing);
		infoHousing.setIvalue(0);
		infoExpands.add(infoHousing);
		//room
		InfoExpand infoRoom = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "room");
		infoRoom.setKeyword("room");
		infoRoom.setSvalue(String.valueOf(this.room));
		infoRoom.setIvalue(this.room);
		infoExpands.add(infoRoom);
		//parlor
		InfoExpand infoParlor = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "parlor");
		infoParlor.setKeyword("parlor");
		infoParlor.setSvalue(String.valueOf(this.parlor));
		infoParlor.setIvalue(this.parlor);
		infoExpands.add(infoParlor);
		//wc
		InfoExpand infoWc = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "wc");
		infoWc.setKeyword("wc");
		infoWc.setSvalue(String.valueOf(this.wc));
		infoWc.setIvalue(this.wc);
		infoExpands.add(infoWc);
		//floor
		InfoExpand infoFloor = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "floor");
		infoFloor.setKeyword("floor");
		infoFloor.setSvalue(String.valueOf(this.floor));
		infoFloor.setIvalue(this.floor);
		infoExpands.add(infoFloor);
		//totalfloor
		InfoExpand infoTotalfloor = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "totalfloor");
		infoTotalfloor.setKeyword("totalfloor");
		infoTotalfloor.setSvalue(String.valueOf(this.totalfloor));
		infoTotalfloor.setIvalue(this.totalfloor);
		infoExpands.add(infoTotalfloor);
		//mianji
		InfoExpand infoMianji = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "mianji");
		infoMianji.setKeyword("mianji");
		infoMianji.setSvalue(String.valueOf(this.mianji));
		infoMianji.setIvalue((int)(Float.parseFloat(mianji)*10));
		infoExpands.add(infoMianji);
		//minPrice
		InfoExpand infoMinPrice = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "minPrice");
		infoMinPrice.setKeyword("minPrice");
		infoMinPrice.setSvalue(String.valueOf(this.minPrice));
		if(StringUtils.isBlank(this.minPrice)){
			infoMinPrice.setIvalue(0);
		}else{
			infoMinPrice.setIvalue((int)(Float.parseFloat(minPrice)*10));
		}
		infoExpands.add(infoMinPrice);
		//houseType
		Parameter pHouseType = this.getParameterService().findParameterById(this.houseType);
		InfoExpand infoHouseType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseType");
		infoHouseType.setKeyword("houseType");
		infoHouseType.setSvalue(pHouseType.getParamName());
		infoHouseType.setIvalue(this.houseType);
		infoExpands.add(infoHouseType);
		//houseFitType
		Parameter pHouseFitType = this.getParameterService().findParameterById(this.houseFitType);
		InfoExpand infoHouseFitType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseFitType");
		infoHouseFitType.setKeyword("houseFitType");
		infoHouseFitType.setSvalue(pHouseFitType.getParamName());
		infoHouseFitType.setIvalue(this.houseFitType);
		infoExpands.add(infoHouseFitType);
		//houseHireroomType
		Parameter pHouseHireroomType = this.getParameterService().findParameterById(this.houseHireroomType);
		InfoExpand infoHouseHireroomType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseHireroomType");
		infoHouseHireroomType.setKeyword("houseHireroomType");
		infoHouseHireroomType.setSvalue(pHouseHireroomType.getParamName());
		infoHouseHireroomType.setIvalue(this.houseHireroomType);
		infoExpands.add(infoHouseHireroomType);
		//houseTowardType
		Parameter pHouseTowardType = this.getParameterService().findParameterById(this.houseTowardType);
		InfoExpand infoHouseTowardType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseTowardType");
		infoHouseTowardType.setKeyword("houseTowardType");
		infoHouseTowardType.setSvalue(pHouseTowardType.getParamName());
		infoHouseTowardType.setIvalue(this.houseTowardType);
		infoExpands.add(infoHouseTowardType);
		//houseConfineType
		Parameter pHouseConfineType = this.getParameterService().findParameterById(this.houseConfineType);
		InfoExpand infoHouseConfineType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseConfineType");
		infoHouseConfineType.setKeyword("houseConfineType");
		infoHouseConfineType.setSvalue(pHouseConfineType.getParamName());
		infoHouseConfineType.setIvalue(this.houseConfineType);
		infoExpands.add(infoHouseConfineType);
		//houseHirepayType
		Parameter pHouseHirepayType = this.getParameterService().findParameterById(this.houseHirepayType);
		InfoExpand infoHouseHirepayType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseHirepayType");
		infoHouseHirepayType.setKeyword("houseHirepayType");
		infoHouseHirepayType.setSvalue(pHouseHirepayType.getParamName());
		infoHouseHirepayType.setIvalue(this.houseHirepayType);
		infoExpands.add(infoHouseHirepayType);
		//
		//houseAllocation
		InfoExpand infoHouseAllocation = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseAllocation");
		infoHouseAllocation.setKeyword("houseAllocation");
		if(houseAllocation==null || houseAllocation.isEmpty()){
			infoHouseAllocation.setSvalue("");
		}else{
			infoHouseAllocation.setSvalue(Util.list2String(houseAllocation));
		}
		infoHouseAllocation.setIvalue(0);
		infoExpands.add(infoHouseAllocation);
		//houseMetroType
		Parameter pHouseMetroType = this.getParameterService().findParameterById(this.houseMetroType);
		InfoExpand infoHouseMetroType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "houseMetroType");
		infoHouseMetroType.setKeyword("houseMetroType");
		infoHouseMetroType.setSvalue(pHouseMetroType.getParamName());
		infoHouseMetroType.setIvalue(this.houseMetroType);
		infoExpands.add(infoHouseMetroType);
		
		info = this.getInfoService().updateInfo(info, infoExpands);
		return "doupdate";
	}

}
